﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Aliyeye.Car.Net.Utility;

namespace Aliyeye.Car.Net.Dal
{
    public class Accounts_PermissionCategories
    {
        public Accounts_PermissionCategories()
        { }
        public int Add(Model.Accounts_PermissionCategories model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@CategoryID", SqlDbType.Int,4),
					new SqlParameter("@Description", SqlDbType.VarChar,255)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.Description;

            int roleId = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_PermissionCategories_ADD", parameters);
            if (roleId > 0)
            {
                return roleId;
            }
            else
            {
                return 0;
            }
        }
        public bool Update(Model.Accounts_PermissionCategories model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@CategoryID", SqlDbType.Int,4),
					new SqlParameter("@Description", SqlDbType.VarChar,255)};
            parameters[0].Value = model.CategoryID;
            parameters[1].Value = model.Description;
            int intResult = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_PermissionCategories_Update", parameters);

            if (intResult > 0)
                return true;
            else
                return false;
        }
        public bool Delete(int Id)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = Id;
            int intResult = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "Accounts_PermissionCategories_Delete", parameters);

            if (intResult > 0)
                return true;
            else
                return false;
        }
        public Model.Accounts_PermissionCategories GetModel(int ClassID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@ClassID", SqlDbType.Int,4)};
            parameters[0].Value = ClassID;

            Model.Accounts_PermissionCategories model = new Model.Accounts_PermissionCategories();
            DataSet ds = SqlHelper.GetDataFormDataSet(CommandType.StoredProcedure, "Accounts_PermissionCategories_GetModel", parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CategoryID"].ToString() != "")
                {
                    model.CategoryID = int.Parse(ds.Tables[0].Rows[0]["CategoryID"].ToString());
                }
                model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CategoryID,Description ");
            strSql.Append(" FROM Accounts_PermissionCategories ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SqlHelper.Query(strSql.ToString());
        }
    }
}
